package cn.edu.ujs.coor.controller;

import cn.edu.ujs.coor.request.IdRequest;
import cn.edu.ujs.coor.request.field.FieldAddRequest;
import cn.edu.ujs.coor.request.field.FieldUpdateRequest;
import cn.edu.ujs.coor.response.JsonResponse;
import cn.edu.ujs.coor.service.FieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "/field")
public class FieldController {

    @Autowired
    private FieldService fieldService;

    @RequestMapping(value = "/add")
    public JsonResponse create (@RequestBody @Valid FieldAddRequest request) {
        fieldService.add(request);
        return JsonResponse.success();
    }

    @RequestMapping(value = "/update")
    public JsonResponse update (@RequestBody @Valid FieldUpdateRequest request) {
        fieldService.update(request);
        return JsonResponse.success();
    }

    @RequestMapping(value = "/delete")
    public JsonResponse delete (@RequestBody @Valid IdRequest request) {
        fieldService.delete(request);
        return JsonResponse.success();
    }
}
